$(function(){
  // 弹窗样式
  function layerCss(){
    $(".layui-layer").css("border-radius","10px")
    $(".layui-layer-setwin .layui-layer-close2").css({"right":"-40px","top":"0px"});
    $(".layui-layer-ico").css("background","url("+jumpUrl+"/img/question2/iconlayer.png)");
  }
	// 我的商品
  var page = ''
  commodity_url(page);
  function commodity_url(page){
  	var jumpdelete = jumpUrl+"/center/order/list?page="+page+"&rows_per_page=10";
    var loading = '<div class="loading">加载中...</div>';
    $(".commodity-box").append(loading);
  	$.get(jumpdelete, function(data){
        }, "json").error(function(data) {
          var status_code = $.parseJSON(data.responseText);
          layer.msg(status_code.message);
        }).success(function(data) {
        	$(".loading").remove();
           var obj = data.data;
           console.info(obj);
           if(obj.length>9){
            $(".item_pager .loadMore").css("display","block");
           }
            var str = '';
            for (var i = 0; i < obj.length; i++) {
              str+='<ul class="Whitebg10r">'
                str+='<li class="Greytitle"><span>订单号：'+obj[i].order_no+'</span> <span class="fr">创建时间：'+obj[i].created_at+'</span></li>'
                str+='<li class="waitpay-type">'
                  str+='<div class="lv-portrait" style="padding: 10px;"></div>'
                  str+='<div class="waitpay-info">'
                    str+='<p><span class="font18 colorE">订单金额：</span>'+obj[i].unit_price+'元</p>'
                    str+='<p><span class="font18 colorE">订单信息：</span>'+obj[i].type_name+'</p>'
                    str+='<p><span class="font18 colorE">订单状态：</span>待付款</p>'
                  str+='</div>'
                  str+='<div class="butbox">'
                    str+='<span class="butD js_Popup03" data-href="'+obj[i].id+'" style="margin-bottom: 10px;">取消订单</span>'
                    str+='<a class="butD" href="'+jumpUrl+'/center/question_order/'+obj[i].id+'/to_pay">支付订单</a>'
                  str+='</div>'
                str+='</li>'
              str+='</ul>'
            };
          $(".commodity-box").append(str);
          $(document).on( "click", ".to_pay_ing", function(e) {
            var loading = layer.msg('加载中...', {icon: 16});
          });
    });
  }
    //滚动条拉到底部的时候去获取新的数据
  $(document).on("click",".loadMore",function(e){
      $(".item_pager .loadMore").css("display","none");
      var cuA = parseInt($(".loadmore").attr("data-href"));
      $(".loadmore").attr("data-href",cuA+1);
      var page = cuA+1;
      commodity_url(page);
      stopDefault(e);
  });
  
  $(document).on( "click", ".js_Popup03", function(e) {
    surePay();
    var id = $(this).attr("data-href");
    var $this = $(this);
    var url = jumpUrl+"/center/question/"+id+"/cancel"
    $(document).on('click', '#js-pay-now', function(e){
      $.post(url,{},function(data){
          },'json').error(function(data) {
              var obj = $.parseJSON(data.responseText);
              layer.msg(obj.error_messages);
          }).success(function(data) {
              layer.msg("取消成功");
              window.location.href=skipUrl;
          });
          stopDefault(e);
    });
  });
  $(document).on('click', '#js-close', function(e){
    layer.closeAll(); 
  });
  //弹出确认取消订单
  function surePay(){
    var Popup03 = $(".Popup03");
        layer.open({
          type: 1, //基本层类型  可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）。 若你采用layer.open({type: 1})方式调用，则type为必填项（信息框除外）
          title: false, //标题
          closeBtn: true,  //关闭按钮
          shade:0.3,  //遮罩默认是0.3透明度
          area: ['350px', '300px'],
          skin: 'yourclass', //样式类名
          content: Popup03 //内容 
      });
      layerCss()
  };
});
